package com.shop.cereshop.business.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shop.cereshop.business.service.buyer.CereBuyerUserService;
import com.shop.cereshop.business.service.shop.CereShopVisitService;
import com.shop.cereshop.business.utils.ContextUtil;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.shop.CereShopVisit;
import com.shop.cereshop.commons.domain.shop.bo.CereShopVisitBo;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/shop/visit")
/**
 * 注解方式生成日志对象，指定topic生成对象类名
 */
@Slf4j(topic = "CereShopVisitVController")
@Api(value = "店铺访问模块", tags = "店铺访问模块")
public class CereShopVisitVController {

    @Autowired
    private CereShopVisitService cereShopVisitService;

    @Autowired
    private CereBuyerUserService cereBuyerUserService;

    @GetMapping("/queryList")
    @ApiOperation(value = "访客列表")
    public Result queryPageList(CereShopVisitBo bo, HttpServletRequest request)throws CoBusinessException {
        Long shopId = ContextUtil.getShopId();
        bo.setShopId(shopId);
        return new Result(   cereShopVisitService.queryPageList(bo), CoReturnFormat.SUCCESS);
    }

    @GetMapping("/getTotal")
    @ApiOperation(value = "获取店铺访问量")
    public Result<Integer> getTotal(Long shopId){
        int count = cereShopVisitService.count(new LambdaQueryWrapper<CereShopVisit>()
                .eq(CereShopVisit::getShopId, shopId));
        return new Result<>(count, CoReturnFormat.SUCCESS);
    }

}
